let pendingMap = new Map()

const getPendingUrl = (config) => {
	return [config.method, config.url].join("&") + uni.$u.queryParams(config.data) + uni.$u.queryParams(config.params)
}

export default {
	// 添加请求
	addPending(config) {
		new Promise((resolve) => {
			const url = getPendingUrl(config)
			config.getTask = (task) => {
				if (!pendingMap.has(url)) {
					pendingMap.set(url, task)
				} else {
					task.abort()
				}
				resolve()
			}
		})
	},
	// 移除请求
	removePending(config) {
		const url = getPendingUrl(config)
		pendingMap.delete(url)
	}
}